{extend name="app/admin/view/base.html" /}
{block name="main"}
<div class="layui-form">
	<div class="layui-form-item" style="margin-top: 20px;">
		<label class="layui-form-label">是否开启：</label>
		<div class="layui-input-block">
			<input type="checkbox" name="sitemessage_is_open" value="1" {if $sitemessage_is_open == 1}checked{/if} lay-skin="switch">
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label"><span class="required"></span>模板内容</label>
		<div class="layui-input-inline">
			<textarea  placeholder="" class="layui-textarea ns-len-long" readonly>{if $info}{$info.content}{/if}</textarea>
		</div>
	</div>
	<input type="hidden" name="keywords" value="{$keywords}" />
	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button type="reset" class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>
</div>
{/block}
{block name="script"}
<script>
	layui.use(['form', 'colorpicker'], function() {
		var form = layui.form,
			repeat_flag = false; //防重复标识
		form.render();

		form.on('submit(save)', function(data) {
			console.log(data.field);
			if (repeat_flag) return;
			repeat_flag = true;

			$.ajax({
				url: ns.url("sitemessage://admin/message/edit"),
				data: data.field,
				dataType: 'JSON',
				type: 'POST',
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.confirm('编辑成功', {
							title:'操作提示',
							btn: ['返回列表', '继续操作'],
							yes: function(){
								location.href = ns.url("admin/message/lists")
							},
							btn2: function() {
								location.reload();
							}
						});
					} else {
						layer.msg(res.message);
					}
				}
			});
		});
	});

	function back() {
		location.href = ns.url("admin/message/lists");
	}
</script>
{/block}